package classificator;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

/**
 *
 * @author Administrator
 */
public class TreeContainer extends Container {
    
    Proxy proxy = Proxy.getIstance();
    
    public TreeContainer(){
        super();
        initPanels();
    }
    
    public static void main(String[] args){
        TreeContainer c = new TreeContainer();
        JFrame f = new JFrame();
        f.add(c);
        f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Dimension SCREEN_SIZE = new Dimension(510, 410);
        f.setMinimumSize(SCREEN_SIZE);
        f.setPreferredSize(SCREEN_SIZE);
        f.setVisible(true);
    }

    private void initPanels() {
        JPanel jpTree, jpTreeConstruction, jpTreeInput, jpPrediction, 
                jpStartPredicting, jpPredictionQuery, jpMessage;
        JRadioButton jrbDb, jrbFile;
        JButton jbTreeConstruction, jbStartPrediction, jbContinue;
        
        //Container cp = this.getContentPane();
        this.setLayout(new GridBagLayout());
        
        GridBagConstraints gbcExternal = new GridBagConstraints();
        gbcExternal.gridx = 0;
        gbcExternal.gridy = 0;
        jpTree = new JPanel();
        jpTree.setMinimumSize(new Dimension(500,120));
        jpTree.setBorder(BorderFactory.createTitledBorder("Tree Settings"));
        this.add(jpTree, gbcExternal);
        
        jpTreeConstruction = new JPanel(new BorderLayout());
        jpTreeConstruction.setBorder(BorderFactory.createTitledBorder("Tree Construction"));
        jrbDb = new JRadioButton("Reading tree from db");
        jrbFile = new JRadioButton("Reading tree from file");
        ButtonGroup bg = new ButtonGroup();
        bg.add(jrbDb);
        bg.add(jrbFile);
        jpTreeConstruction.add(jrbDb, BorderLayout.NORTH);
        jpTreeConstruction.add(jrbFile, BorderLayout.SOUTH);
        jpTree.add(jpTreeConstruction);
        
        jpTreeInput = new JPanel();
        jpTreeInput.setBorder(BorderFactory.createTitledBorder("Input Parameters"));
        jpTreeInput.add(new JLabel("Data"));
        JTextField jtfNameData = new JTextField(15);
        jpTreeInput.add(jtfNameData);
        jbTreeConstruction = new JButton("Tree");
        jbTreeConstruction.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e){
                proxy.treeConstruction();
            }
        });
        jpTreeInput.add(jbTreeConstruction);
        jpTree.add(jpTreeInput);
        
        gbcExternal.gridy = 1;
        jpPrediction = new JPanel(new GridBagLayout());
        jpPrediction.setMinimumSize(new Dimension(500,280));
        jpPrediction.setBorder(BorderFactory.createTitledBorder("Prediction Settings"));
        this.add(jpPrediction, gbcExternal);
        
        GridBagConstraints gbcInternal = new GridBagConstraints();
        gbcInternal.gridx = 0;
        gbcInternal.gridy = 0;
        jpStartPredicting = new JPanel();
        jpStartPredicting.setMinimumSize(new Dimension(490,60));
        jpStartPredicting.setBorder(BorderFactory.createTitledBorder("To start prediction process"));
        jpPrediction.add(jpStartPredicting, gbcInternal);
        jbStartPrediction = new JButton("START");
        jpStartPredicting.add(jbStartPrediction);
        
        gbcInternal.gridy = 1;
        jpPredictionQuery = new JPanel();
        jpPredictionQuery.setMinimumSize(new Dimension(490,90));
        jpPredictionQuery.setBorder(BorderFactory.createTitledBorder("Define the example to be predicted"));
        jpPrediction.add(jpPredictionQuery, gbcInternal);
        JLabel jlQuery = new JLabel();
        jpPredictionQuery.add(jlQuery);
        JTextField jtfAnswer = new JTextField(2);
        jpPredictionQuery.add(jtfAnswer);
        jbContinue = new JButton("CONTINUE");
        jpPredictionQuery.add(jbContinue);
        
        gbcInternal.gridy = 2;
        jpMessage = new JPanel();
        jpMessage.setMinimumSize(new Dimension(490,90));
        jpMessage.setBorder(BorderFactory.createTitledBorder("Message Area"));
        JLabel jlMsgArea = new JLabel();
        jlMsgArea.setPreferredSize(new Dimension(480,85));
        jpMessage.add(jlMsgArea);
        jpPrediction.add(jpMessage, gbcInternal);
    }
}